USE MASTER

DROP DATABASE Studial
GO

CREATE DATABASE Studial
GO

USE Studial
GO

IF exists ( select * from sysobjects where id = object_id(N'[GROUP_G]') and objectproperty (id, N'isusertable') = 1)
	DROP TABLE GROUP_G
GO

IF exists ( select * from sysobjects where id = object_id(N'[GROUPMEMBERS]') and objectproperty (id, N'isusertable') = 1)
	DROP TABLE GROUPMEMBERS
GO

IF exists ( select * from sysobjects where id = object_id(N'[TOPIC]') and objectproperty (id, N'isusertable') = 1)
	DROP TABLE TOPIC
GO

IF exists ( select * from sysobjects where id = object_id(N'[COMMENT]') and objectproperty (id, N'isusertable') = 1)
	DROP TABLE COMMENT
GO

IF exists ( select * from sysobjects where id = object_id(N'[LIKE_L]') and objectproperty (id, N'isusertable') = 1)
	DROP TABLE LIKE_L
GO

CREATE TABLE LIKE_L
(
	UserID INT NOT NULL,
	PostID INT NOT NULL,
	Type_T VARCHAR(150) NOT NULL,
	CONSTRAINT PK_LIKE_L PRIMARY KEY (UserID, PostID)
)
GO

CREATE TABLE GROUP_G
(
	GroupID INT NOT NULL,
	Name_N VARCHAR(150) NOT NULL,
	Description_D VARCHAR(1024),
	StartDay DATETIME NOT NULL,
	Admin_A VARCHAR(150) NOT NULL,
	CONSTRAINT PK_GROUP_G PRIMARY KEY (GroupID)
)
GO

CREATE TABLE GROUPMEMBERS
(
	GroupID INT NOT NULL,
	UserID INT NOT NULL,
	CONSTRAINT PK_GROUPMEMBERS PRIMARY KEY (GroupID, UserID)
)
GO

CREATE TABLE COMMENT
(
	CommentID INT NOT NULL,
	UserID INT NOT NULL,
	TopicID INT NOT NULL,
	Link VARCHAR(1024),
	Likes INT,
	Content_C VARCHAR(1024) NOT NULL,
	Time_T DATETIME NOT NULL,
	CONSTRAINT PK_COMMENT PRIMARY KEY (CommentID)
)
GO

CREATE TABLE TOPIC
(
	TopicID INT NOT NULL,
	UserID INT NOT NULL,
	HomeID INT NOT NULL,
	Type_T VARCHAR(150) NOT NULL,
	Content_C VARCHAR(1024) NOT NULL,
	Link VARCHAR(1024),
	Likes INT,
	Comments INT,
	Time_T DATETIME NOT NULL,
	CONSTRAINT PK_TOPIC PRIMARY KEY (TopicID)
)